package exam.test12;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Endstart
 * Date: 2020-11-11
 * Time: 3:01
 */
public class Duphash {

    public boolean duplicated(int k, int[] T, int m, int keysChecked[]) {
        int hashOne = hashOne(k, m);
        int hashTwo = hashTwo(k);
        int[] findIndex = new int[m];
        int i = 0;
        while (true) {
            int hash = (hashOne + i * hashTwo) % m;
            if (T[hash] != -1) {
                for (int j = 0; j < i; j++) {
                    if (findIndex[j] == hash) {
                        return false;
                    }
                }
                keysChecked[i] = T[hash];
                findIndex[i] = hash;
            } else {
               return true;
            }
            i++;
        }
    }

    private int hashOne(int k, int m) {
        return k % m;
    }

    private int hashTwo(int k) {
        return 7 - k % 7;
    }

    public static void main(String[] args) {
        int[] T = {-1, -1, -1, 10, -1, 5, 3, 6, -1, -1, 6};
        int[] keyChecked = {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1};

        Duphash duphash = new Duphash();
        boolean check = duphash.duplicated(17, T, 11, keyChecked);
        System.out.println("----------");
    }


}
